﻿using FilmBlowingMachine.Template;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using System;
using System.Collections.Generic;
using System.Text;

namespace FilmBlowingMachine.ViewModel
{
    class MainViewModel:ViewModelBase
    {
        public MainViewModel()
        {
            Dashboard = new DashboardView();
            DataMonitor = new DataMonitorView();
            Settings = new SettingsView();
            Modules = new List<Module>();
            Modules.Add(new Module() { Code = "ChartLine", Name = "Dashboard", TypeName = "", Auth = 0 });
            Modules.Add(new Module() { Code = "DatabaseSync", Name = "数据监控", TypeName = "", Auth = 0 });
            Modules.Add(new Module() { Code = "CogOutline", Name = "设置", TypeName = "", Auth = 0 });
            Modules.Add(new Module() { Code = "About", Name = "关于", TypeName = "", Auth = 0 });

            ExitCommand = new RelayCommand(ExitCmd);
            ExpandMenuCommand = new RelayCommand(() =>
            {
                Messenger.Default.Send("", "ExpandMenu");
            });
            OpenPageCommand = new RelayCommand<string>(t => OpenPageCmd(t));
        }

        public List<Module> Modules { get; set; }
        public DashboardView Dashboard { get; set; }
        public DataMonitorView DataMonitor { get; set; }
        public SettingsView Settings { get; set; }
        public object page;
        public object Page
        {
            get { return page; }
            set { page = value; RaisePropertyChanged(); }
        }

        /// <summary>
        /// 菜单栏伸缩
        /// </summary>
        public RelayCommand ExpandMenuCommand { get; private set; }
        public RelayCommand ExitCommand { get; private set; }
        public RelayCommand<string> OpenPageCommand { get; set; }

        private void ExitCmd()
        {
            Messenger.Default.Send(true, "ExitMainWindow");
        }
        private void OpenPageCmd(string Name)
        {
            switch (Name)
            {
                case "Dashboard":
                    Page = Dashboard;
                    break;
                case "数据监控":
                    Page = DataMonitor;
                    break;
                case "设置":
                    Page = Settings;
                    break;
                case "关于":
                    break;
                default:
                    break;
            }
        }
    }
}
